package com.byinsight.web.actions;

import com.byinsight.service.DimensionService;
import com.byinsight.service.ExpenseService;
import com.byinsight.web.actions.util.UserTokenEncoder;

import eg.backend.manager.DimensionManager;
import eg.backend.manager.ExpenseManager;

abstract public class CheckSessionAction extends BaseAction {
	private static final long serialVersionUID = 1L;
	protected String userToken;
	
	protected DimensionManager 	dimensionManager;
	protected ExpenseManager 	expenseManager;
	protected ExpenseService 	expenseService;
	protected DimensionService 	dimensionService;
	
	@Override
	public String execute() throws Exception {
		checkSession();
		return super.execute();
	}
	
	protected void checkSession() throws Exception {
		if(userToken == null || UserTokenEncoder.getId(userToken)== null)
			throw new Exception("Invalid token");
	}
	
	/* struts */
	public void setUserToken(String userToken) {
		this.userToken = userToken;
	}

	public void setDimensionManager(DimensionManager dimensionManager) {
		this.dimensionManager = dimensionManager;
	}

	public void setExpenseManager(ExpenseManager expenseManager) {
		this.expenseManager = expenseManager;
	}

	public void setExpenseService(ExpenseService expenseService) {
		this.expenseService = expenseService;
	}

	public void setDimensionService(DimensionService dimensionService) {
		this.dimensionService = dimensionService;
	}

}
